package com.stx.blog.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.stx.blog.dao.BlogDAO;
import com.stx.blog.entity.BlogEntity;
import com.stx.blog.service.BlogService;
import com.stx.blog.vo.BlogVO;
import com.stx.category.entity.CategoryEntity;
import com.stx.category.vo.CategoryVO;

public class BlogServiceImpl implements BlogService {

	private BlogDAO blogdao;

	@Override
	public List<BlogVO> listBlog(String userID) {
		List<BlogVO> blogList = new ArrayList<BlogVO>();
		List<BlogEntity> entityList = blogdao.listBlog(userID);

		for (BlogEntity entity : entityList) {

			BlogVO vo = new BlogVO();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			blogList.add(vo);

		}

		return blogList;
	}

	@Override
	public BlogVO getBlogByBid(String bid) {
		BlogEntity blogEntity = blogdao.getBlogByBid(bid);
		BlogVO blogVO = new BlogVO();
		BeanUtils.copyProperties(blogEntity, blogVO);
		return blogVO;
	}

	@Override
	public List<BlogVO> getBlogByUserID(String userID) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addBlog(BlogVO blogvo) {
		// TODO Auto-generated method stub
		blogdao.addBlog(blogvo);
	}

	@Override
	public void deleteBlog(String bid) {
		blogdao.deleteBlog(bid);

	}

	@Override
	public void editBlog(BlogVO blogvo) {
		blogdao.editBlog(blogvo);

	}

	public BlogDAO getBlogdao() {
		return blogdao;
	}

	public void setBlogdao(BlogDAO blogdao) {
		this.blogdao = blogdao;
	}

	@Override
	public List<CategoryVO> listCatgoryToAddBlog() {
		List<CategoryVO> voList = new ArrayList<CategoryVO>();

		List<CategoryEntity> entityList = blogdao.listCatgoryToAddBlog();

		for (CategoryEntity entity : entityList) {

			CategoryVO vo = new CategoryVO();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			voList.add(vo);

		}
		return voList;
	}

	@Override
	public CategoryVO getCategoryVOByCid(String cID) {
		CategoryEntity categoryEntity = blogdao.getCategoryEntityByCid(cID);
		CategoryVO categoryVO = new CategoryVO();
		BeanUtils.copyProperties(categoryEntity, categoryVO);
		return categoryVO;
	}

	@Override
	public List<BlogVO> listAllBlog() {
		List<BlogVO> blogList = new ArrayList<BlogVO>();
		List<BlogEntity> entityList = blogdao.listAllBlog();

		for (BlogEntity entity : entityList) {

			BlogVO vo = new BlogVO();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			blogList.add(vo);

		}

		return blogList;
	}

}
